package com.tianzeculture.stagebao.activity.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.squareup.picasso.Picasso;
import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.artist.ArtistActivity;
import com.tianzeculture.stagebao.bean.ArtistsBean;
import com.tianzeculture.stagebao.bean.User;
import com.tianzeculture.stagebao.util.Util;
import com.tianzeculture.stagebao.view.SqImageView;

import java.util.List;

import static com.tianzeculture.stagebao.net.base.AppBaseRestUsageV2.PICTURE_URL;

/**
 * Created by Administrator on 2018/5/29 0029.
 * 人才库
 */

public class TalentAdapter extends RecyclerView.Adapter<TalentAdapter.RecyclerViewHolder> {
    Context context;
    List<User> users;

    public TalentAdapter(Context context, List<User> users) {
        this.context = context;
        this.users = users;
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_talent, parent, false);
        View view1 = LayoutInflater.from(context).inflate(R.layout.item_talent_first, parent, false);
        if (viewType == -1)
            return new RecyclerViewHolderFirst(view1);
        else
            return new RecyclerViewHolder(view);
    }


    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position) {
        holder.setData(position);
    }

    @Override
    public int getItemCount() {
        return users.size();
    }

    @Override
    public int getItemViewType(int position) {
        return users.get(position).getIsFirst();
    }

    class RecyclerViewHolder extends RecyclerView.ViewHolder {

        ImageView ivArtists;
        TextView tvArtists;

        public RecyclerViewHolder(View itemView) {
            super(itemView);
            ivArtists = itemView.findViewById(R.id.ivArtists);
            tvArtists = itemView.findViewById(R.id.tvArtists);
        }

        public void setData(final int position) {
            ivArtists.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    context.startActivity(new Intent(context, ArtistActivity.class).putExtra("otherId", users.get(position).getId()));
                }
            });
            tvArtists.setText(users.get(position).getNickname());
            Glide.with(context).load(PICTURE_URL + users.get(position).getImgurl()).placeholder(R.mipmap.test).error(R.mipmap.test).dontAnimate().into(ivArtists);
//            Picasso.with(context).load(PICTURE_URL + users.get(position).getImgurl()).into(ivArtists);
        }
    }

    class RecyclerViewHolderFirst extends RecyclerViewHolder {

        ImageView ivFirst;

        public RecyclerViewHolderFirst(View itemView) {
            super(itemView);

            ivFirst = itemView.findViewById(R.id.ivFirst);
        }

        public void setData(int position) {
            Picasso.with(context).load(R.mipmap.wutaibao).into(ivFirst);
        }
    }
}